*
*  PMODE34x - test for two simultaneous graphic modes
*
         ORG      $4000
         put      $4000
*
itype		equ      $f7			* INTERRUPT ENABLED: 0=V - 1=H
count    equ      $f8			* counter to change PMODE
*
instal   ORCC     #$50     	* Disable IRQ/FIRQ interrupts
         LDX      #ISR			* get new IRQ-dispatch routine			
         CMPX		$010D			* is it already installed?
         BEQ      UNINST		* uninstall it - disable control
*
ENABLE   CLR      <ITYPE     	* VSYNC ENABLED
       	STA   	$FFC0			* clear SAM V0
       	STA   	$FFC3			* set   SAM V1
       	STA   	$FFC5			* set   SAM V2
       	STA   	$FFC6			* start of graph memory = $0C00
       	STA   	$FFC9				*
       	STA   	$FFCB				*
       	STA   	$FFCC				*
       	STA   	$FFCE				*
       	STA   	$FFD0				*
       	STA   	$FFD2				*
		 	LDA      $FF03    	* enable Frame Sync Interrupt
         ORA      #$01				*
         STA      $FF03				*
         LDA      $FF01    	* Disable Horizontal Sync Interrupt
         ANDA     #$FE				*
         STA      $FF01				*
         BRA      CHGVEC		* change to the new IRQ-dispatcher into vector
*
UNINST   LDX      #$C727		* get std default value - if no disks then: 9D3D
         LDA      $FF01   		* disable Horizontal Sync Interrupt
         ANDA     #$FE				*
         STA      $FF01				*
         LDA      $FF03   		* enable Frame Sync Interrupt
         ORA      #$01				*
         STA      $FF03				*
*
CHGVEC   STX      $010D   		* set IRQ dispatch routine
         ANDCC    #$AF    		* enable IRQ/FIRQ interrupts
         RTS              		* return to caller
*
isr		tst      <itype		* which IRQ source is enabled?
			bne      hsync			* zero, so HSYNC
*
vsync		lda      $ff02			* clear VSYNC IRQ flag
			lda      #$e0			* set PIA1 = 1110 0--- (colorset 0)
			sta      $ff22			* set PMODE3
         lda      $FF01   		* enable HSync Interrupt
         ora      #$01				*
         sta      $FF01				*
         lda		#100			* number of sync pulses to count
         sta      <count		* save counter
         inc      <itype      * flag for HSYNC
			bra      goout       * go out
*
hsync		lda      $FF00   		* clear HSYNC IRQ flag
			dec      <count		* decrement counter
			tst      <count		* reached zero?
			bne      goout			* no, go out
			sync
			lda      #$f8        * set PIA1 = 1111 1--- (colorset 1)
			sta      $ff22       * set PMODE4
         lda      $FF01   		* disable HSync Interrupt
         anda     #$fe				*
         sta      $FF01				*
         clr		<itype		* flag for VSYNC
goout		rti		* it's faster ... but loses SOUND - PLAY compatibility
*
